﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using LibHuman;
using System.Data;
namespace Human
{
	/// <summary>
	/// Summary description for frmThangnam.
	/// </summary>
	public class frmCNHS : System.Windows.Forms.Form
	{
        AccessData mDB = new AccessData();
        Language lan = new Language();
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtThang;
		private System.Windows.Forms.TextBox txtNam;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button cmdOk;
		private System.Windows.Forms.Button cmdCancel;
        string s_mmyy = "", s_userid;
        public string m_thang = "", m_nam = "";
        private GroupBox groupBox1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmCNHS(string s_user)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
			s_userid=s_user;
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmCNHS));
            this.label1 = new System.Windows.Forms.Label();
            this.txtThang = new System.Windows.Forms.TextBox();
            this.txtNam = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.cmdOk = new System.Windows.Forms.Button();
            this.cmdCancel = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.label1.Location = new System.Drawing.Point(19, 24);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(48, 16);
            this.label1.TabIndex = 0;
            this.label1.Text = "Tháng: ";
            // 
            // txtThang
            // 
            this.txtThang.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtThang.ForeColor = System.Drawing.Color.Blue;
            this.txtThang.Location = new System.Drawing.Point(64, 22);
            this.txtThang.MaxLength = 2;
            this.txtThang.Name = "txtThang";
            this.txtThang.Size = new System.Drawing.Size(48, 22);
            this.txtThang.TabIndex = 1;
            this.txtThang.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtThang.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtThang_KeyPress);
            this.txtThang.Validated += new System.EventHandler(this.txtThang_Validated);
            this.txtThang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtThang_KeyDown);
            // 
            // txtNam
            // 
            this.txtNam.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtNam.ForeColor = System.Drawing.Color.Blue;
            this.txtNam.Location = new System.Drawing.Point(159, 22);
            this.txtNam.MaxLength = 4;
            this.txtNam.Name = "txtNam";
            this.txtNam.Size = new System.Drawing.Size(48, 22);
            this.txtNam.TabIndex = 3;
            this.txtNam.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtNam.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtThang_KeyPress);
            this.txtNam.Validated += new System.EventHandler(this.txtNam_Validated);
            this.txtNam.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtNam_KeyDown);
            // 
            // label2
            // 
            this.label2.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.label2.Location = new System.Drawing.Point(123, 24);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(48, 16);
            this.label2.TabIndex = 2;
            this.label2.Text = "Năm:";
            // 
            // cmdOk
            // 
            this.cmdOk.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdOk.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.cmdOk.Image = ((System.Drawing.Image)(resources.GetObject("cmdOk.Image")));
            this.cmdOk.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cmdOk.Location = new System.Drawing.Point(34, 62);
            this.cmdOk.Name = "cmdOk";
            this.cmdOk.Size = new System.Drawing.Size(78, 26);
            this.cmdOk.TabIndex = 4;
            this.cmdOk.Text = "   Đồn&g ý";
            this.cmdOk.Click += new System.EventHandler(this.cmdOk_Click);
            // 
            // cmdCancel
            // 
            this.cmdCancel.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdCancel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(160)))));
            this.cmdCancel.Image = global::Human.Properties.Resources.close_r;
            this.cmdCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cmdCancel.Location = new System.Drawing.Point(116, 62);
            this.cmdCancel.Name = "cmdCancel";
            this.cmdCancel.Size = new System.Drawing.Size(78, 26);
            this.cmdCancel.TabIndex = 5;
            this.cmdCancel.Text = "  &Bỏ qua";
            this.cmdCancel.Click += new System.EventHandler(this.button2_Click);
            // 
            // groupBox1
            // 
            this.groupBox1.Location = new System.Drawing.Point(6, 1);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(212, 111);
            this.groupBox1.TabIndex = 6;
            this.groupBox1.TabStop = false;
            // 
            // frmCNHS
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(225, 120);
            this.Controls.Add(this.cmdCancel);
            this.Controls.Add(this.cmdOk);
            this.Controls.Add(this.txtNam);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.txtThang);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.groupBox1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmCNHS";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Chọn tháng năm";
            this.Load += new System.EventHandler(this.frmThangnam_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void frmThangnam_Load(object sender, System.EventArgs e)
		{
			txtThang.Text=DateTime.Now.Month.ToString().PadLeft(2,'0');
			txtNam.Text=DateTime.Now.Year.ToString();
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
            m_thang = "";
            m_nam = "";
            this.Close();
		}

		private void txtThang_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtNam_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void cmdOk_Click(object sender, System.EventArgs e)
		{
			s_mmyy=txtThang.Text+txtNam.Text.Substring(2);
            m_thang = txtThang.Text;
            m_nam = txtNam.Text;
            this.Close();
            
		}     
		private void txtNam_Validated(object sender, System.EventArgs e)
		{
			try
			{
				if ((int.Parse(txtNam.Text)<DateTime.Now.Year-4)||(int.Parse(txtNam.Text)>DateTime.Now.Year+1))
				{
					MessageBox.Show(lan.Change_language_MessageText("Năm không hợp lệ!"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
					txtNam.Focus();
					return ;
				}
			}
			catch
			{
				txtNam.Text=DateTime.Now.Year.ToString();
			}
		}

		private void txtThang_Validated(object sender, System.EventArgs e)
		{
			txtThang.Text=txtThang.Text.PadLeft(2,'0');
			try
			{
				if ((int.Parse(txtThang.Text)<1)||(int.Parse(txtThang.Text)>12))
				{
					MessageBox.Show(lan.Change_language_MessageText("Tháng không hợp lệ!"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
					txtThang.Focus();
					return ;
				}
			}
			catch
			{
				txtThang.Text=DateTime.Now.Month.ToString().PadLeft(2,'0');
			}
		}

        private void txtThang_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < '0' || e.KeyChar > '9')&& e.KeyChar!='\b')
                e.KeyChar = '\0';
        }
	}
}
